package com.blb.ssh.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.blb.ssh.entity.User;
import com.blb.ssh.exception.BusinessException;
import com.blb.ssh.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class IndexAction extends ActionSupport	{

	private User user;
	
	private UserService userService;

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String index(){
		System.out.println("hello action...");
		return "login";
	}
	
	/**
	 * @return
	 */
	public String login(){
		HttpServletRequest request = ServletActionContext.getRequest();
		try{
			userService.login(user.getUsername(), user.getPassword());
		}catch(BusinessException e){
			e.printStackTrace();
			request.setAttribute("msg", e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}
}
